package com.xxljob.demo.core.route;

import com.xxljob.demo.core.route.stragety.ExecutorRouteFirst;
import com.xxljob.demo.core.route.stragety.ExecutorRouteLast;
import com.xxljob.demo.core.util.I18nUtil;

import java.util.Objects;

/**
 * @Author：YH
 * @Description：
 * @Date:Created in 2022/5/21 15:54
 */
public enum ExecutorRouteStrategyEnum {


    FIRST(I18nUtil.getString("jobconf_route_first"), new ExecutorRouteFirst()),
    LAST(I18nUtil.getString("jobconf_route_last"), new ExecutorRouteLast()),
    SHARDING_BROADCAST(I18nUtil.getString("jobconf_route_shard"), null);

    private String title;
    private ExecutorRouter router;

    ExecutorRouteStrategyEnum(String title, ExecutorRouter router) {
        this.title = title;
        this.router = router;
    }

    public ExecutorRouter getRouter() {
        return router;
    }

    //根据不同策略选
    public static ExecutorRouteStrategyEnum match(String name, ExecutorRouteStrategyEnum defaultIterm) {
        if (Objects.nonNull(name)) {

            for (ExecutorRouteStrategyEnum item : ExecutorRouteStrategyEnum.values()) {
                if (item.name().equals(name)) {
                    return item;
                }
            }
        }

        return defaultIterm;
    }
}
